int treesize(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    return 1 + treesize(root->left) + treesize(root->right);
}
void preorder(struct TreeNode* root, int* arr, int* p)
{
    if (root == NULL)
    {
        return;
    }
    arr[(*p)++] = root->val;
    preorder(root->left, arr, p);
    preorder(root->right, arr, p);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = treesize(root);
    int* arr = (int*)malloc(*returnSize * sizeof(int));
    int p = 0;
    preorder(root, arr, &p);
    return arr;
}